<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>

<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>注册页面</title>
  <style>
    body {
      margin: 0;
      padding: 0;
      text-align: center;
      background: url("${base}/Desert.jpg");
      background-size: cover;
    }

    #c {
      margin: auto;
      margin-top: 70px;
      opacity: 0.8;
      width: 1000px;
      height: 600px;
    }
    #left {
      width: 700px;
      height: 600px;
      background: rgb(255, 255, 255);
      margin: auto;
      border-radius: 20px;
      padding-top: 10px;
      position: relative;
    }
    input {
      width: 270px;
      border-top-style: hidden;
      border-right-style: hidden;
      border-left-style: hidden;
      background: none;
      margin: 0;
      text-align: center;
    }
    select {
      width: 270px;
      border-top-style: hidden;
      border-right-style: hidden;
      border-left-style: hidden;
      background: none;
      margin: 0;
      text-align: center;
    }
    p {
      color: gray;
      height: 30px;
    }
    #file {
      margin-top: 10px;
      color: #616161;
    }
    button {
      margin-top: 50px;
      width: 250px;
      height: 33px;
      border-radius: 20px;
      border: 0px;
      background-color: #c0ca33;
      color: #FFF;
      font-size: 16px;
    }
    span {
      position: absolute;
      left: 30px;
      color: red;
      font-size: 13px;
    }
  </style>
</head>
<body>
<div id="c">
  <div id="left">
    <h1>修改老师信息</h1>
    <form action="${base}/user/update" method="post" enctype="multipart/form-data" onsubmit="return checked()">
      <input type="hidden" name="id" value="${upd.id}">
      <p><span id="acterror"></span>账号：<input id="act" type="text" name="account" readonly="readonly" value="${upd.account}"></p>
      <p><span id="pwerror"></span>密码：<input id="pw" type="text" name="password" value="${upd.password}"></p>
      <p><span id="unerror"></span>昵称：<input id="un" type="text" name="name" value="${upd.name}"></p>
      <p><span id="pherror"></span>手机：<input id="ph" type="text" name="phone" value="${upd.phone}"></p>
      <p>性别：男<input style="width: 40px;" type="radio" name="sex" <c:if test="${upd.sex eq 1}">checked</c:if>  value="1">女<input style="width: 40px;margin-right: 160px" type="radio" name="sex" <c:if test="${upd.sex eq 0}">checked</c:if> value="0"></p>
      <p><span id="clerror"></span>班级：<select id="select" name="classid">
        <option value="-1">无班级</option>
        <c:forEach var="c" items="${classList}">
          <option value="${c.id}" <c:if test="${c.id eq upd.classid}"> selected</c:if> >${c.name}</option>
        </c:forEach>
      </select></p>
      <p><span id="myerror"></span><a style="text-decoration-line: none; color: gray" href="javascript:;" onclick="$('#file').click()">请选择头像</a>
        <input name="myHead" onchange="show(this)" id="file" type="file" style="display: none"></p>
      <p><img id="img" style="width: 80px;height: 80px;border-radius: 50%" src="${base}/upload/${upd.headpic}" alt="图片一"></p>
      <input type="hidden" name="roleid" value="${upd.roleid}">
      <p><button id="sub" type="submit">确认修改</button><button type="button" onclick="history.back(-1)">返回</button></p>
      <p></p>
    </form>
  </div>
</div>
<script src="${base}/jquery-3.0.0.min.js"></script>
<script>
    var isExit = true;
    $("#select").blur(function () {
        var value = $(this).val();
        $.post('${base}/user/checkTeacher?classid=' + value, function (a) {
            if (a == "该班级已有老师!") {
                $("#clerror").css("color", "red").html(a);
                isExit = false;
            } else {
                $("#clerror").css("color", "green").html(a);
                isExit = true;
            }
        })
    })
    function show(obj) {
        var imgFile=obj.files[0];
        var src=window.URL.createObjectURL(imgFile);
        document.getElementById("img").setAttribute("src",src);
    }
    if (${!empty error}) {
        lightyear.loading('show');
        // 假设ajax提交操作
        setTimeout(function () {
            lightyear.loading('hide');
            lightyear.notify('${error}', 'danger', 0);
        }, 0)
    }
    var isPw = true;
    $("#pw").blur(function () {
        if (pw.value==null||pw.value==""){
            $("#pwerror").css("color","red").html("请输入密码！");
            isPw = false;
        } else {
            $("#pwerror").css("color","green").html("密码可用！");
            isPw = true;
        }
    })
    var isUn = true;
    $("#un").blur(function () {
        if (un.value==null||un.value=="") {
            $("#unerror").css("color", "red").html("请输入昵称");
            isUn = false;
        } else {
            $("#unerror").css("color", "green").html("昵称可用");
            isUn = true;
        }
    })
    var isPh = true;
    $("#ph").blur(function () {
        if (ph.value==null||ph.value=="") {
            $("#pherror").css("color", "red").html("请输入手机号");
            isPh = false;
        } else {
            var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
            if (!myreg.test(ph.value)) {
                $("#pherror").css("color", "red").html("无效的手机号！");
                isPh = false;
            } else {
                $("#pherror").css("color", "green").html("号码可用");
                isPh = true;
            }
        }
    })
    function checked() {
        if (isExit && isPw && isUn && isPh) return true;
        else return false;
    }
</script>
</body>
</html>

